package com.rachel.apkupdate.model;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.Binder;
import android.os.Environment;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.util.Log;

import com.rachel.apkupdate.ToolUtils.TypeConverUtils;
import com.rachel.apkupdate.ToolUtils.log;
import com.rachel.apkupdate.entris.FileInfo;
import com.rachel.apkupdate.presenter.IUpdatePresenter;

import java.io.File;

/**
 * Created by zhengshaorui on 2017/4/15.
 */

public class DownloadService extends Service {
    private Context mContext;
    private FileInfo mFileInfo;
    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        mFileInfo = (FileInfo) intent.getSerializableExtra("fileinfo");

        File file = new File(TypeConverUtils.getFilePath());
        if (!file.exists()){
            file.mkdir();
        }
        mFileInfo.setFileDir(file);

        log.d("service: "+mFileInfo);
        return mBinder;
    }


    private DownloadBinder mBinder = new DownloadBinder();
    class DownloadBinder extends Binder{
        public void startDownload(IUpdatePresenter callback){
            new DownloadTask(mFileInfo, callback);
        }
      //  public void getDownloadTask()
    }
    @Override
    public void onCreate() {
        super.onCreate();
        mContext = this;
    }


}
